import schedule
import time
from fetch_data import *  # 假设这是更新数据的函数


def job():
    print("Updating data...")
    boards_overview, boards_detail = boards_data()
    boards_overview.to_csv("板块交易概况.csv", index=False)
    boards_detail.to_csv("板块个股交易概况.csv", index=False)
    # 写出数据更新相关信息
    with open("./data_log.json", "w", encoding="utf-8") as f:
        json.dump({"数据更新时间": datetime.now().strftime("%Y-%m-%d %H:%M:%S")}, f)
    print("-" * 100)
    print("板块交易概况、板块个股交易概况已写出到本地！")
    print("Data updated.")


# 设置定时任务，例如每天凌晨1点更新数据
schedule.every(1).minutes.do(job)

while True:
    schedule.run_pending()
    time.sleep(1)
